<template>
	<view class="comment-section">
		<!-- 评论排序选项卡 -->
		<view class="comment-tabs">
			<view v-for="(tab, index) in tabs" :key="index" @click="selectTab(index)"
				:class="{ active: currentTab === index }">
				{{ tab }}
			</view>
		</view>

		<!-- 评论列表 -->
		<view class="comment-list">
			<view class="comment-item" v-for="(comment, index) in comments" :key="index">
				<view class="comment-header">
					<image class="avatar" :src="comment.avatar" mode="aspectFill"></image>
					<text class="username">{{ comment.username }}</text>
				</view>

				<view class="comment-content">
					{{ comment.content }}
				</view>

				<view class="comment-footer">
					<text class="date">{{ comment.date }}</text>
					<view class="actions">
						<view class="action-item">
							<image class="icon" src="@/static/image/赞.png"></image>
							<text>{{ comment.replyCount }}</text>
						</view>
<!-- 						<view class="action-item">
							<image class="icon" src="@/static/image/头像.png"></image>
							<text>{{ comment.likeCount || '点赞' }}</text>
						</view> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'CommentSection',
		props: {
			comments: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				tabs: ['评论', '最热', '最新'],
				currentTab: 0
			}
		},
		computed: {
			filteredComments() {
				if (this.currentTab === 1) {
					return [...this.comments].sort((a, b) => b.likeCount - a.likeCount)
				} else if (this.currentTab === 2) {
					return [...this.comments].sort((a, b) => new Date(b.date) - new Date(a.date))
				}
				return this.comments
			}
		},
		created() {
			console.log('Received comments:', this.comments);
		},
		methods: {
			selectTab(index) {
				this.currentTab = index
			}
		}
	}
</script>

<style scoped>
	.comment-section {
		padding: 20rpx;
	}

	.comment-tabs {
		display: flex;
		margin-bottom: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.comment-tabs view {
		padding: 15rpx 30rpx;
		font-size: 28rpx;
		color: #666;
	}

	.comment-tabs .active {
		color: #007AFF;
		border-bottom: 4rpx solid #007AFF;
	}

	.comment-item {
		padding: 20rpx 0;
		border-bottom: 1rpx solid #f5f5f5;
	}

	.comment-header {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;
	}

	.avatar {
		width: 70rpx;
		height: 70rpx;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.username {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
	}

	.comment-content {
		font-size: 30rpx;
		color: #333;
		line-height: 1.6;
		margin-bottom: 15rpx;
	}

	.comment-footer {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.date {
		font-size: 24rpx;
		color: #999;
	}

	.actions {
		display: flex;
	}

	.action-item {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		font-size: 24rpx;
		color: #999;
	}

	.icon {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}
</style>